﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using HML.Design;

namespace HML
{
    /// <summary>
    /// SingleAccordion标签节点
    /// </summary>
    public class SingleAccordionLabelNode : SingleAccordionNode
    {
        #region 公开方法

        /// <summary>
        /// 复制节点
        /// </summary>
        /// <param name="copyChildrens">是否复制子节点</param>
        /// <returns></returns>
        public override SingleAccordionNode Copy(bool copyChildrens = false)
        {
            SingleAccordionLabelNode node = new SingleAccordionLabelNode()
            {
                MouseAnimationEnabled = this.MouseAnimationEnabled,
                LRAnimationDistance = this.LRAnimationDistance,
                SplitterLineVisible = this.SplitterLineVisible,
                TextLRMargin = this.TextLRMargin,
                Text = this.Text,
                Tag = this.Tag,
                ImageVisible = this.ImageVisible,
                Image = this.Image
            };
            node.StyleAppearance.SplitterLineColor = this.StyleAppearance.SplitterLineColor;
            node.StyleAppearance.Normal.BackColor = this.StyleAppearance.Normal.BackColor;
            node.StyleAppearance.Normal.TextColor = this.StyleAppearance.Normal.TextColor;
            node.StyleAppearance.Enter.BackColor = this.StyleAppearance.Enter.BackColor;
            node.StyleAppearance.Enter.TextColor = this.StyleAppearance.Enter.TextColor;

            return node;
        }

        /// <summary>
        /// 获取节点鼠标动画启用状态（节点未添加到控件返回 false）
        /// </summary>
        /// <returns></returns>
        public override bool GetMouseAnimationEnabled()
        {
            SingleAccordion sa = this.Owner;
            return this.Owner == null ? false : sa.LabelNodeStyle.MouseAnimationEnabled;
        }

        /// <summary>
        /// 获取节点鼠标动画总时间（节点未添加到控件返回0）
        /// </summary>
        /// <returns></returns>
        public override int GetMouseAnimationAllTime()
        {
            SingleAccordion sa = this.Owner;
            return this.Owner == null ? 0 : sa.LabelNodeStyle.MouseAnimationAllTimer;
        }

        #endregion

        #region 属性

        private StyleObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleObject(this);
                return this.stateAppearance;
            }
        }

        #endregion

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class StyleObject
        {
            private SingleAccordionLabelNode owner = null;
            internal StyleObject(SingleAccordionLabelNode owner) { this.owner = owner; }

            #region 私有方法

            /// <summary>
            /// 刷新控件
            /// </summary>
            private void Invalidate()
            {
                if (this.owner != null)
                {
                    this.owner.Invalidate();
                }
            }

            #endregion

            #region 属性

            private Color splitterLineColor = Color.Empty;
            /// <summary>
            /// 分隔线颜色
            /// </summary>
            [Description(" 分隔线颜色")]
            [PropertyOrder(-198)]
            [DefaultValue(typeof(Color), "")]
            [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
            public Color SplitterLineColor
            {
                get { return this.splitterLineColor; }
                set
                {
                    if (this.splitterLineColor == value)
                        return;

                    this.splitterLineColor = value;
                    this.Invalidate();
                }
            }

            private ItemObject normal;
            /// <summary>
            /// 正常状态
            /// </summary>
            [Description("正常状态")]
            [PropertyOrder(-194)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ItemObject Normal
            {
                get
                {
                    if (this.normal == null)
                        this.normal = new ItemObject(this);
                    return this.normal;
                }
            }

            private ItemObject enter;
            /// <summary>
            /// 鼠标进入状态
            /// </summary>
            [Description("鼠标进入状态")]
            [PropertyOrder(-192)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public ItemObject Enter
            {
                get
                {
                    if (this.enter == null)
                        this.enter = new ItemObject(this);
                    return this.enter;
                }
            }

            #endregion

            [TypeConverter(typeof(PropertyOrderConverter))]
            public class ItemObject
            {
                private StyleObject owner = null;
                internal ItemObject(StyleObject owner) { this.owner = owner; }

                #region 私有方法

                /// <summary>
                /// 刷新控件
                /// </summary>
                private void Invalidate()
                {
                    if (this.owner != null && this.owner.owner != null)
                    {
                        SingleAccordionLabelNode singleAccordionCategoryNode = (SingleAccordionLabelNode)this.owner.owner;
                        singleAccordionCategoryNode.Invalidate();
                    }
                }

                #endregion

                #region 属性

                private Color backColor = Color.Empty;
                /// <summary>
                /// 背景颜色
                /// </summary>
                [Description("背景颜色")]
                [PropertyOrder(-158)]
                [DefaultValue(typeof(Color), "")]
                [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                public Color BackColor
                {
                    get { return this.backColor; }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }

                private Color textColor = Color.Empty;
                /// <summary>
                /// 文本颜色
                /// </summary>
                [Description("文本颜色")]
                [PropertyOrder(-157)]
                [DefaultValue(typeof(Color), "")]
                [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                public Color TextColor
                {
                    get { return this.textColor; }
                    set
                    {
                        if (this.textColor == value)
                            return;

                        this.textColor = value;
                        this.Invalidate();
                    }
                }

                #endregion

            }

        }

    }

}
